<template>
  <div>
    <!-- <h1>评论</h1> -->
    <!-- 输入任意文本 -->
  <van-field v-model="value" label="评论："
  autosize
  type="textarea"
  placeholder="请输入评论内容"
  />
  <van-row>
  <van-col span="8"></van-col>
  <van-col span="8">
    <van-button round type="info" size="small" @click="toComment()">提交评论</van-button>
  </van-col>
  <van-col span="8"></van-col>
</van-row>
  
  </div>
</template>

<script>

import CommentAPI from "@/api/CommentAPI.js"

export default {
   name: 'MusicComment',
   data() {
    return {
      value: '',
      TbComment: {
        commentId: '',
        userId: '',
        musicId: '',
        commentText: '',
        countLike: ''
      }
    }
   },
  
   props: {
    props_musicId: {
      required: true,
      type: String
    }

   },

   created(){
    this.TbComment.musicId = this.props_musicId
        //给$bus绑定musicId事件
      //  this.$bus.$on("musicId", (data) => {
      // this.TbComment.userId=data
      // this.$toast("data")
    // })

   },

   mounted(){

    // 获取音乐Id
    // this.$bus.$on("musicId",(data) =>{
    //  this.TbComment.musicId = data
    // })
   },
   methods: {
    toComment(){
      // this.$toast(this.value)
      // this.console(this.value)
      this.TbComment.commentText=this.value
      // this.$toast( this.TbComment.commentText)
        // 发布评论
      var result = CommentAPI.addComment(this.TbComment)
        // 发布评论
       result.then((val) => {
        if (val.success) {
        this.$toast("发布评论成功")
          
        // 提交完成后返回页面刷新
            //  this.$router.go(0)
        }
        else {
         console.log(val.errorMsg);
         this.$toast(val.errorMsg);
             }
      });
  
    }
   },


}
</script>

<style>

</style>